﻿using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Net;
using MultiThreadedWorkerRole;
using ThreadedWorkerRole;
using ThreadedWorkerRoleLib;

namespace WorkerRole
{
    public class WorkerRole : ThreadedRoleEntryPoint
    {

        List<WorkerEntryPoint> GetWorkerRoles()
        {
            // Add all your worker roles here and they will run in their own thread
            return new List<WorkerEntryPoint> {
                new EmailWorker {
                    MaxThreadSleepInSeconds = int.Parse(ConfigurationManager.AppSettings["EmailWorkerMaxThreadSleepSeconds"])
                }
                // , new MessageWorker()    // Example of another worker role, this would work in its own thread seperate from any other workers
            };
        }

        public override bool OnStart()
        {
            // Set the maximum number of concurrent connections 
            ServicePointManager.DefaultConnectionLimit = int.Parse(ConfigurationManager.AppSettings["DefaultConnectionLimit"]);

            return OnStart(GetWorkerRoles().ToArray());
        }

        public override void Run()
        {
            // This is a sample worker implementation. Replace with your logic.
            Trace.TraceInformation("Worker Role entry point called");

            base.Run();
        }

    }
}
